local zishucup__shuli = fk.CreateSkill{
  name = "zishucup__shuli",
}

Fk:loadTranslationTable{
  ["zishucup__shuli"] = "述理",
  [":zishucup__shuli"] = "出牌阶段限一次，你可以进行一次判定，然后进行一次拼点：若判定结果为♣，你摸一张牌；若判定与拼点的共计三张牌花色各不同，你摸一张牌；若你拼点且赢，你摸一张牌。",

  ["#zishucup__shuli-choose"] = "述理：请与一名角色拼点！",

  ["$zishucup__shuli1"] = " ",
  ["$zishucup__shuli2"] = " ",
}

zishucup__shuli:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(zishucup__shuli.name, Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local suits = {}
    local judge = {
      who = player,
      reason = zishucup__shuli.name,
      pattern = ".|.|club",
    }
    room:judge(judge)
    table.insertIfNeed(suits, judge.card.suit)
    if judge:matchPattern() and not player.dead then
      player:drawCards(1, zishucup__shuli.name)
    end
    local targets = table.filter(room:getOtherPlayers(player), function(p) return player:canPindian(p) end)
    if #targets > 0 then
      local tos = player.room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = zishucup__shuli.name,
        cancelable = false,
        prompt = "#zishucup__shuli-choose",
      })
      if #tos > 0 then
        local to = tos[1]
        local pindian = player:pindian({to}, self.name)
        table.insertIfNeed(suits, pindian.fromCard.suit)
        table.insertIfNeed(suits, pindian.results[tos[1]].toCard.suit)
        if #suits == 3 and not player.dead then
          player:drawCards(1, zishucup__shuli.name)
        end
        if pindian.results[to].winner == player and not player.dead then
          player:drawCards(1, zishucup__shuli.name)
        end
      end
    end
  end,
})

return zishucup__shuli
